---
redirect_from:
  - /config/databases/elasticsearch
---

# Elasticsearch

<CommunitySupportedDriver dataSource="Elasticsearch" />

<SuccessBox>

Elastic integration, supported by Cube, is also available in Cube Cloud on
[Enterprise Premier](https://cube.dev/pricing) tier. [Contact
us](https://cube.dev/contact) for details.

</SuccessBox>

## Prerequisites

To connect to an [Elasticsearch][elasticsearch] database, use `CUBEJS_DB_URL`
with the username and password embedded in the URL, if required.

<WarningBox>

If you're not using [Elastic Cloud][elastic-cloud], you **must** specify
`CUBEJS_DB_ELASTIC_QUERY_FORMAT`.

</WarningBox>

## Setup

### Manual

For a self-hosted Elasticsearch instance, add the following to a `.env` file in
your Cube project:

```dotenv
CUBEJS_DB_TYPE=elasticsearch
CUBEJS_DB_URL=https://my.elasticsearch.host:9200
CUBEJS_DB_ELASTIC_QUERY_FORMAT=json
```

For an Elasticsearch instanced hosted by [Elastic.co][elastic-co], add the
following to a `.env` file in your Cube project:

```dotenv
CUBEJS_DB_TYPE=elasticsearch
CUBEJS_DB_URL=https://my.elasticsearch.host:9200
CUBEJS_DB_ELASTIC_APIKEY_ID=VuaCfGcBCdbkQm-e5aOx
CUBEJS_DB_ELASTIC_APIKEY_KEY=ui2lp2axTNmsyakw9tvNnw
```

## Environment Variables

| Environment Variable             | Description                                                                                                                                                                              | Possible Values                        | Required |
| -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------- | :------: |
| `CUBEJS_DB_URL`                  | The URL for a database                                                                                                                                                                   | A valid database URL for Elasticsearch |    ✅    |
| `CUBEJS_DB_ELASTIC_QUERY_FORMAT` | By default, queries return data in JDBC format, but you can also return data in standard Elasticsearch JDBC, JSON, CSV, YAML or raw formats (only JSON and JDBC are currently supported) | `json`, `jdbc`                         |    ❌    |
| `CUBEJS_DB_ELASTIC_OPENDISTRO`   | If `true`, then use the Open Distro for Elasticsearch                                                                                                                                    | `true`, `false`                        |    ❌    |
| `CUBEJS_DB_ELASTIC_APIKEY_ID`    | [ID of the API key from elastic.co][elastic-docs-api-keys]                                                                                                                               | A valid Elastic.co API key ID          |    ❌    |
| `CUBEJS_DB_ELASTIC_APIKEY_KEY`   | [Value of the API key from elastic.co][elastic-docs-api-keys]                                                                                                                            | A valid Elastic.co API key value       |    ❌    |
| `CUBEJS_CONCURRENCY`             | The number of concurrent connections each queue has to the database. Default is `2`                                                                                                      | A valid number                         |    ❌    |
| `CUBEJS_DB_MAX_POOL`             | The maximum number of concurrent database connections to pool. Default is `8`                                                                                                            | A valid number                         |    ❌    |

## SSL

Cube does not require any additional configuration to enable SSL as
Elasticsearch connections are made over HTTPS.

[elastic-co]: https://elastic.co/
[elastic-cloud]: https://cloud.elastic.co/
[elasticsearch]: https://www.elastic.co/elasticsearch/
[elastic-docs-api-keys]:
  https://www.elastic.co/guide/en/kibana/master/api-keys.html#create-api-key
